var bidding4purchase = new Vue({

    el: "#bidding4purchase",

    data: {
        goodsType: '',
        pmbm: '',//品目编码
        fileList: [],
        merchant: [],//参与竞价商家信息
        merchants: '',//存放竞价商家信息
        options: [],
        biddingName: [],
        //时间范围信息
        TimeRange: [],
        //横向菜单列表
        goodsType: [],
        //采购单清单信息
        ordersDetails: [],
        //采购单信息
        urchaseAndOrdersdetail: [],
        //采购清单
        QuoteOrCompare: {
            biddingName: '', //查找询价单位
            commodityName: '',
            commodityNum: '',
            shippingAddress: '',
            deadline: '',
            startTime: '',
            priceCap: '',
            postscript: '',
            contrastType: '',
            number: '',
            purchaseId: ''
        },
        urchaseAndOrdersdetails: [],
        ordersDetails: []
    },
    //提交时间方法
    methods: {
        confirmFrom: function () {
            var _this = this;
            $("#fileSubmit").submit();

            var merchantsStr = _this.merchants.join("-");
            _this.QuoteOrCompare.startTime = _this.TimeRange[0];
            _this.QuoteOrCompare.deadline = _this.TimeRange[1];
            $.post("/home/quote_or_compare/addQuoteAndCompare",
                {"QuoteOrCompare": JSON.stringify(_this.QuoteOrCompare), "merchants": merchantsStr},
                function (data) {
                    var status = data.data.status;
                    if (data.code == 200) {
                        if (status === "true") {
                            _this.$notify({
                                message: "询价成功",
                                type: 'success'
                            });
                            $("#wrap-left").load("http://" + window.location.host + "/home/personOffers.html", function () {

                            });
                        }
                    } else {
                        _this.$notify({
                            message: data.data.message,
                            type: 'error'
                        });
                        return;
                    }
                    // $("#wrap-left").load("http://" + window.location.host + "/home/PurchaseAndOrdesdetail.html", function () {
                    //     PurchaseAndOrdesdetail.urchaseAndOrdersdetail = _this.urchaseAndOrdersdetails;
                    //     PurchaseAndOrdesdetail.ordersDetails = _this.ordersDetails;
                    // });


                });

        },

        handleRemove: function (file, fileList) {
            console.log(file, fileList);
        },
        handlePreview: function (file) {
            console.log(file);
        },
        selectMechant: function () {
            var _this = this;
            debugger
            $.post("/home/merchant/selectByPmbm",
                {"pmbm": _this.pmbm, "goodsType": _this.goodsType},
                function (data) {
                    debugger
                    //初始化商家列表项
                    for (var i = 0; i < data.data.merchant.length; i++) {
                        var map = {};
                        map.value = data.data.merchant[i].id;
                        map.label = data.data.merchant[i].companyName;
                        _this.merchant.push(map);
                    }
                });
        },
        checkRole: function (str) {
            var _this = this;
            var RegPrice = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if (!RegPrice.test(str)) {
                _this.$notify({
                    message: "请正确填写,必须为数字.",
                    type: 'error'
                });
            }
        },
    },

    //页面加载后的初始化方法
    created: function () {
        var _this = this;
        _this.QuoteOrCompare.commodityName = _this.ordersDetails.pmmc;
        _this.QuoteOrCompare.commodityNum = _this.ordersDetails.sl;
        _this.QuoteOrCompare.purchaseId = _this.ordersDetails.id;
        PurchaseAndOrdesdetail.dialogFormVisible = false;
        PurchaseAndOrdesdetail.dialogFormDtils = false;

        //查询跟自己 有关系的地址
        $.post("/home/addressManager/selectByUserAndTypeCheck", "", function (data) {
            debugger
            if(data.data.addressManagers.address!=null&&data.data.addressManagers.address!=''){
                _this.QuoteOrCompare.shippingAddress = data.data.addressManagers.address;
            }
        });
    }
});